package javaz.jaudio.info;

import java.io.File;
import java.io.FilenameFilter;

import com.mpatric.mp3agic.Mp3File;

/**
 * @author natu
 * @date 2014-03-14
 * @maven http://mvnrepository.com/artifact/com.mpatric/mp3agic/0.8.2
 * @github https://github.com/mpatric/mp3agic
 * @Ex http://grepcode.com/file/repo1.maven.org/maven2/com.mpatric/mp3agic/0.8.1/com/mpatric/mp3agic/app/Example.java
 * @More http://www.java2s.com/Open-Source/Java_Free_Code/Example/Download_mp3agic_examples_Free_Java_Code.htm
 * @FilenameFilter http://stackoverflow.com/questions/19932962/use-of-filenamefilter
 */
public class ChangeInfo {

	public static void main(String[] args) {
		String srcPath = "T:/English/TOEIC 600/Recorder";

		File folder = new File(srcPath);
		for (File file : folder.listFiles(new FilenameFilter() {
			@Override
			public boolean accept(File dir, String name) {
				return name.toLowerCase().endsWith(".mp3");
			}
		})) {
			String fileName = file.getName(); // Lesson 01.mp3
			String filePath = file.getPath(); // D:/music/Lesson 01.mp3
			String parentPath = file.getParent(); // D:/music
			String dstPath = parentPath + "/store/" + fileName;

			try {
				Mp3File f = new Mp3File(filePath);
				if (f.hasId3v1Tag()) {
					f.getId3v1Tag().setTitle(fileName.replace(".mp3", ""));
					f.getId3v1Tag().setAlbum("TOEIC 600 WORDS");
					f.getId3v1Tag().setArtist("Tu Ngo");
				}
				if (f.hasId3v2Tag()) {
					f.getId3v2Tag().setTitle(fileName.replace(".mp3", ""));
					f.getId3v2Tag().setAlbum("TOEIC 600 WORDS");
					f.getId3v2Tag().setArtist("Tu Ngo");
				}
				f.save(dstPath);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

}
